package com.wyp168.renrenfilm.core;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Semaphore;

public class LeetcodeSolution001 {
    public static void main(String[] args) {
//        String key = "the quick brown fox jumps over the lazy dog";
//        String message = "vkbs bs t suepuv";
//
//        LeetcodeSolution001 leetcodeSolution001 = new LeetcodeSolution001();
//
//        String s = leetcodeSolution001.decodeMessage(key, message);
//
//        System.out.println(s);

        /////////////////////////////////////////////////////////////////////////////////////////////


//        LeetcodeSolution001 leetcodeSolution001 = new LeetcodeSolution001();
//        leetcodeSolution001.testThreadLocal();

        Integer a = 100;
        int b = 100;

        System.out.println(a == b);
    }




    public String decodeMessage(String key, String message) {
        //获取到真实的key
        key = removeRepeatString(key);

        StringBuilder sb = new StringBuilder();

        for(int i = 0; i < message.length(); i ++) { //解密字符串
            char tempItem = message.charAt(i);
            if (tempItem != ' ') {
                int index = key.indexOf(String.valueOf(tempItem));
                sb.append((char) (97 + index));
            } else {
                sb.append(" ");
            }
        }
        return sb.toString();
    }

    public String removeRepeatString(String s) {
        boolean[] isAppear = new boolean[26];
        int count = 0;
        int index = 0;
        StringBuilder result = new StringBuilder();

        while (count < 26 && index < s.length()) {
            char item = s.charAt(index ++);
            if (item != ' ' && !isAppear[item - 'a']) {
                isAppear[item - 'a'] = true;
                result.append(item);
                count ++;
            }
        }
        return result.toString();
    }

    public void testThreadLocal() {
        ThreadLocal t = new ThreadLocal();
        t.set("abc");

        System.out.println(t.get());
        System.out.println(t.get());
        System.out.println(t.get());
        System.out.println(t.get());



    }
}
